<template>
  <div>
    <!-- <头部的导航 -->
    <div id="slider" class="mui-slider ">
				<div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
					<div class="mui-scroll">
						<a :class="item.id===0?'mui-control-item mui-active':'mui-control-item'" href="#item1mobile" data-wid="tab-top-subpage-1.html" v-for="item in category" :key="item.id"  @click="getpohotlist(item.id)">
							{{item.title}}
						</a>
					</div>
				</div>
			</div>
    <!-- 图片信息内容 -->
      <ul class="imglist-contain">
        <router-link tag="li" :to="'/home/photoinfo/'+item.id" v-for="item in photolist" :key="item.id">
          <img v-lazy="item.img_url">
          <!-- 图片下面的文字描述 -->
          <div class="photoinfo">
            <h1>{{item.title}}</h1>
            <p>{{item.zhaiyao}}</p>
          </div>
        </router-link>
      </ul>
  </div>
</template>

<script>
// 引入mui.js文件
import mui from "../../lib/mui/js/mui.js"
export default {
  data(){
   return{
    category:[],
    photolist:"",
   } 
  },
  created(){
    this.getcategory();

    // 获取首页的全部消息
    this.getpohotlist(0);
  },
  // 当组件中的DOM结构被渲染好并放到页面后，会执行这个钩子函数
  mounted(){ 
    // 初始化滑动组件
    mui('.mui-scroll-wrapper').scroll({
    deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  },
  methods:{
    // 获取导航条对应的消息 并加上id为0的消息
    getcategory(){
      this.$http.get("http://www.liulongbin.top:3005/api/getimgcategory").then((result)=>{
        if(result.body.status===0){
          this.category=result.body.message
          this.category.unshift({title:"全部",id:0});
          
        }else{
          Toast("请求失败")
        }
      })
    },
    // 获取服务器图片的方法
    getpohotlist(id){
      this.$http.get("http://www.liulongbin.top:3005/api/getimages/"+id).then((result)=>{
        if(result.body.status===0){
          this.photolist=result.body.message;
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .mui-slider{
    touch-action: pan-x;
  }
  
  .imglist-contain{
    list-style: none;
    padding: 0px 10px;
    margin: 0 0 20px 0;
    li{
      position: relative;
      background: #ccc;
      margin-top: 5px;
      text-align: center;
      box-shadow: 0 0 9px #999;
      img{
      width: 100%;
      vertical-align: middle;
      }
      img[lazy=loading] {
      width: 40px;
      height: 300px;
      margin: auto;
      }

      .photoinfo{
        text-align: left;
        color: white;
        height: 85px;
        position: absolute;
        background: rgba(0,0,0,0.4);
        bottom: 0;
        h1{
          font-size: 14px;
        }
        p{
          font-size: 12px;
          color: white;
        }
      }
    }
  }
</style>
